﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;


namespace InstitutionAssitant
{
    public partial class frmSupervisionCode : Form
    {
        #region 01 自定义属性        
        public Dictionary<string, string> m_dictInfo = new Dictionary<string, string>(); // 回传信息
        #endregion

        public frmSupervisionCode()
        {
            InitializeComponent();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnReturn_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmSupervisionCode_Load(object sender, EventArgs e)
        {

            lblAppCode.Text = this.m_dictInfo["RegistrationCode"];
            lblGoodsCode.Text= this.m_dictInfo["Code"];
            lblGoodsName.Text= this.m_dictInfo["Name"]; 
            lblManu.Text= this.m_dictInfo["Manufacturer"];
            lblSpec.Text= this.m_dictInfo["Spec"];
            lblYBCode.Text= this.m_dictInfo["YBCode"];

            _initDgvTitle();

            // 取溯源码数据
            string strSql = "select SupervisionCode,PackageRatio,CreateTime from TH_GoodsCheckSupervisionCode where Code='{0}'";
            strSql=string.Format(strSql, this.m_dictInfo["Code"]);
            DataTable dt = DbHelper.DBAccess[0]._openSql_Dt(strSql);
            // 显示数据
            CommFun._showDataGridView0(dgvCode1, dt, AppConfig.m_dictFieldWidth[this.Name + "0"], AppConfig.m_dictFieldName[this.Name + "0"]);

            // 取采集溯源码数据
            strSql = "select SupervisionCode,CreateTime from TH_SupervisionCodeCollect where BillCode='{0}' and BillDetailCode='{1}' and GoodsCode='{2}'";
            strSql = string.Format(strSql, this.m_dictInfo["DeliveryCode"], this.m_dictInfo["DeliveryDetailCode"], this.m_dictInfo["Code"]);
            dt = DbHelper.DBAccess[0]._openSql_Dt(strSql);
            // 显示数据
            CommFun._showDataGridView0(dgvCode2, dt, AppConfig.m_dictFieldWidth[this.Name + "1"], AppConfig.m_dictFieldName[this.Name + "1"]);
        }

        public void _initDgvTitle()
        {
            string strInfo = "";
            string strKind = "";
            strKind = this.Name + "0";
            // 存在时不再处理
            if (AppConfig.m_dictFieldName.ContainsKey(strKind))
            {
                return;
            }
            strInfo = "SupervisionCode-追溯标识码,PackageRatio-包装比,CreateTime-时间";
            AppConfig.m_dictFieldName.Add(strKind, strInfo);
            strInfo = "SupervisionCode,PackageRatio,CreateTime";
            AppConfig.m_dictFieldSql.Add(strKind, strInfo);
            strInfo = "SupervisionCode,PackageRatio,CreateTime";
            AppConfig.m_dictField0.Add(strKind, strInfo);
            strInfo = "100,80,400";
            AppConfig.m_dictFieldWidth0.Add(strKind, strInfo);
            // 设置值
            strInfo = AppConfig.m_iniSetup._readValue("Common", string.Format("{0}_Field", strKind), AppConfig.m_dictField0[strKind]).Trim();
            AppConfig.m_dictField.Add(strKind, strInfo);
            strInfo = AppConfig.m_iniSetup._readValue("Common", string.Format("{0}_FieldWidth", strKind), AppConfig.m_dictFieldWidth0[strKind]).Trim();
            AppConfig.m_dictFieldWidth.Add(strKind, strInfo);

            strKind = this.Name + "1";
            // 存在时不再处理
            if (AppConfig.m_dictFieldName.ContainsKey(strKind))
            {
                return;
            }
            strInfo = "SupervisionCode-追溯码,CreateTime-采集时间";
            AppConfig.m_dictFieldName.Add(strKind, strInfo);
            strInfo = "SupervisionCode,CreateTime";
            AppConfig.m_dictFieldSql.Add(strKind, strInfo);
            strInfo = "SupervisionCode,CreateTime";
            AppConfig.m_dictField0.Add(strKind, strInfo);
            strInfo = "200,400";
            AppConfig.m_dictFieldWidth0.Add(strKind, strInfo);
            // 设置值
            strInfo = AppConfig.m_iniSetup._readValue("Common", string.Format("{0}_Field", strKind), AppConfig.m_dictField0[strKind]).Trim();
            AppConfig.m_dictField.Add(strKind, strInfo);
            strInfo = AppConfig.m_iniSetup._readValue("Common", string.Format("{0}_FieldWidth", strKind), AppConfig.m_dictFieldWidth0[strKind]).Trim();
            AppConfig.m_dictFieldWidth.Add(strKind, strInfo);
        }

        private void _showSpecRow()
        {            
            foreach (DataGridViewRow dr in dgvCode1.Rows)
            {
                foreach (DataGridViewCell dc in dr.Cells)
                {
                    dc.Style.Font = new Font("宋体",12);
                }
            }
            foreach (DataGridViewRow dr2 in dgvCode2.Rows)
            {
                foreach (DataGridViewCell dc1 in dr2.Cells)
                {
                    dc1.Style.Font = new Font("宋体",12);
                }
            }
        }
    }
}
